package cn.com.basic.framework.exception.enums.errors;

import cn.com.basic.framework.exception.enums.IErrorCode;

/**
 * 常见数据库异常错误码
 * <p>
 * 值范围 B0400 - B0499
 *
 * @author cuixk
 */
public enum DBError implements IErrorCode {

    /**
     * 数据库异常
     */
    DATASOURCE_ERROR
            ("B0400", "数据库异常"),
    /**
     * 连接失败
     */
    CONNECTION_FAILED
            ("B0401", "连接失败"),
    /**
     * 连接超时
     */
    CONNECTION_TIMEOUT
            ("B0402", "连接超时"),
    /**
     * 新增记录失败
     */
    INSERT_ERROR
            ("B0403", "新增记录失败"),
    /**
     * 删除记录失败
     */
    DELETE_ERROR
            ("B0404", "删除记录失败"),
    /**
     * 修改记录失败
     */
    UPDATE_ERROR
            ("B0405", "修改记录失败"),
    ;

    private final String code;
    private final String description;

    DBError(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getKey() {
        return this.code;
    }

    @Override
    public String getValue() {
        return this.description;
    }

    @Override
    public String toString() {
        return String.format("Code:[%s], Describe:[%s]", this.code, this.description);
    }
}
